/**
 * Setvor project
 */
package setvor.yeild;

/**
 * @author julatec
 *
 */
public abstract class StateBasedIterator<S, T> extends YeildIterator<T> {

	private S currentState;
	
	public StateBasedIterator(S initialState){
		super();
		currentState = initialState;
	}
	
	
	protected static class StateAndValue<S2, T2>{
		
		public T2 value;
		public S2 state;
		
		public StateAndValue(S2 state, T2 value){
			this.value = value;
			this.state = state;
		}
	}
	
	protected abstract StateAndValue<S, T> next(S state);	
	
	public T next(){
		StateAndValue<S, T> newStateAndValue = next(currentState);
		this.currentState = newStateAndValue.state;
		return newStateAndValue.value;
	}
}
